package com.kuafu.latte.transport;

import com.kuafu.latte.exchange.ByteUtil;
import com.kuafu.latte.exchange.Message;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

public class MessageDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext cxt, ByteBuf in, List<Object> list) throws Exception {
        byte[] bytes = new byte[in.readableBytes()];
        in.readBytes(bytes);
        list.add((Message) ByteUtil.byteToObject(bytes));
    }
}
